package name.fowler.refactoring.simplestore.service;

import name.fowler.refactoring.simplestore.Customer;
import name.fowler.refactoring.simplestore.Movie;
import name.fowler.refactoring.simplestore.PriceCode;
import name.fowler.refactoring.simplestore.Rental;

public class FrequentPointsService {

    public static int getBonus(Customer customer) {
        int result = 0;
        for (Rental rental : customer.getRentals()) {
            result += getBonus(rental);
        }
        return result;
    }

    public static int getBonus(Rental rental) {
        int result = 0;
        
        result += getBonus((rental.getMovie()), rental.getDaysRented());

        return result;
    }

    public static int getBonus(Movie movie, int daysRented) {
        PriceCode priceCode = movie.getPriceCode();
        int result = priceCode.getBaseBonus();
        if (daysRented > priceCode.getExtraBonusDays()) {
            result += priceCode.getExtraBonus();
        }
        return result;
    }
}